package com.tobby.camel.camelinaction.chapter6.firsttest;

import java.io.File;

import org.apache.camel.Exchange;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.test.junit4.CamelTestSupport;
import org.junit.Test;

public class FirstTest extends CamelTestSupport {

	@Override
	public RouteBuilder createRouteBuilder() {
		return new RouteBuilder() {

			@Override
			public void configure() throws Exception {
				from("file://target/inbox").to("file://target/outbox");
			}
		};
	}

	@Override
	public void setUp() throws Exception {
		deleteDirectory("target/inbox");
		deleteDirectory("target/outbox");
		super.setUp();
	}

	@Test
	public void testMoveFile() throws Exception {
		template.sendBodyAndHeader("file://target/inbox", "Hello World",
				Exchange.FILE_NAME, "hello.txt");

		Thread.sleep(1000);

		File target = new File("target/outbox/hello.txt");
		assertTrue("File not moved", target.exists());

		String content = context.getTypeConverter().convertTo(String.class, target);
		assertEquals("Hello World", content);
	}

}
